﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>MyClouds：数据字典</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-card">
				<form id="q-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">标识 / 名称</label>
							<div class="layui-input-inline">
								<input type="text" name="dict_type_name" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">字典键 / 值</label>
							<div class="layui-input-inline">
								<input type="text" name="dict_key_value" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">数据状态</label>
							<div class="layui-input-inline">
								<select name="is_enable">
									<option value="">请选择</option>
									<option value="1">启用</option>
									<option value="0">停用</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline">
								<button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="lf-btn-query" type="button">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 查询
								</button>
								<button class="layui-btn layui-btn-primary layui-btn-sm" type="reset">
									<i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
								</button>
							</div>
						</div>

					</div>
				</form>
				<div class="layui-card-body">
					<div style="padding-bottom: 10px;">

						<button id="btn-add" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon layui-icon-add-1 "></i>
							新增</button>
						<button class="layui-btn layui-btn-primary layui-btn-sm layui-btn-disabled" id="btn-batch-del"><i class="layui-icon layui-icon-delete "></i>
							删除</button>
						<!-- <button id="btn-test" class="layui-btn layui-btn-primary layui-btn-sm">测试</button> -->
					</div>
					<table id="t-dict" lay-filter="t-dict"></table>
				</div>
			</div>
		</div>
	</body>
	<script src="../../layuiadmin/layui/layui.js"></script>
	<script>
		layui.config({
			base: '../../layuiadmin/'
		}).extend({
			index: 'lib/index'
		}).use(['index', 'table', 'form', 'myutil'], function() {
			var $ = layui.$,
				form = layui.form,
				myutil = layui.myutil,
				table = layui.table;
			myutil.init();
	$.ajaxSetup({
		headers: {
			"X-Auth-Token": myutil.user().token
		}
	});
			table.render({
				id: 't-dict',
				elem: '#t-dict',
				url: layui.setter.my.surl + 'admin/system/dict/list',
				contentType: 'application/json',
				method: 'post',
				cols: [
						[{
						type: 'checkbox'
						}, {
						field: 'id',
						width: 100,
						title: '字典ID'
						}, {
						field: 'dict_type',
						title: '分组标识',
						width: 150
						}, {
						field: 'dict_name',
						title: '分组名称',
						width: 150
						}, {
						field: 'dict_key',
						title: '字典键',
						width: 150
						}, {
						field: 'dict_value',
						title: '字典值',
						minWidth: 100
						}, {
						field: 'sort_no',
						title: '排序号',
						width: 80
						}, {
						field: 'is_enable',
						title: '数据状态',
						align: 'center',
						templet: function(row) {
							var html = row.is_enable;
							if (row.is_enable == 1) {
								html = '<span class="layui-badge layui-bg-green">启用</span>';
							} else if (row.is_enable == 0) {
								html = '<span class="layui-badge layui-bg-orange">停用</span>';
							}
							return html;
						},
						width: 100
						}, {
						field: 'update_time',
						title: '更新时间',
						width: 160
						}, {
						title: '操作',
						align: 'center',
						fixed: 'right',
						templet: function(row) {
							var editBtn = '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>';
							var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
							return editBtn + delBtn;
						},
						width: 120
						}]
					],
				page: true,
				limit: 15,
				height: 'full-170',
				limits: [10, 15, 20, 50, 100, 200],
				loading: true,
				text: {
					none: '没有符合条件的数据'
				}
			});

			//监听表格操作集
			table.on('tool(t-dict)', function(obj) {
				var row = obj.data;
				if (obj.event === 'del') {
					layer.confirm('确定删除当前数据字典吗？', {
						icon: 3
					}, function(index) {
						myutil.ajax({
							url: layui.setter.my.surl + 'admin/system/dict/delete',
							data: {
								id: row.id
							},
							ok: function(res) {
								layer.alert(res.msg, {
									icon: 1
								});
								fnListTable(myutil.json('#q-form'));
							}
						});
					});
				} else if (obj.event === 'edit') {
					layer.open({
						type: 2,
						anim: 0,
						isOutAnim: false,
						title: '编辑数据字典',
						content: 'dict-form.html?id=' + row.id,
						area: ['550px', '500px'],
						btn: ['确定', '取消'],
						yes: function(index, layero) {
							var submit = layero.find('iframe').contents().find("#btn-edit-submit");
							submit.click();
						}
					});
				}
			});

			//监听表格复选框
			table.on('checkbox(t-dict)', function(obj) {
				var checkStatus = table.checkStatus('t-dict');
				if (checkStatus.data.length == 0) {
					$('#btn-batch-del').addClass('layui-btn-disabled').attr('disabled', "disabled");
				} else {
					$('#btn-batch-del').removeClass('layui-btn-disabled').removeAttr('disabled');
				}
			});

			function fnListTable(where) {
				table.reload('t-dict', {
					where: where
				});
				$('#btn-batch-del').addClass('layui-btn-disabled').attr('disabled', "disabled");
			}

			//查询按钮
			form.on('submit(lf-btn-query)', function(data) {
				fnListTable(data.field);
			});

			//新增窗口
			$('#btn-add').on('click', function() {
				layer.open({
					type: 2,
					anim: 0,
					isOutAnim: false,
					title: '新增数据字典',
					content: 'dict-form.html',
					area: ['550px', '500px'],
					btn: ['确定', '取消'],
					yes: function(index, layero) {
						var submit = layero.find('iframe').contents().find("#btn-add-submit");
						submit.click();
					}
				});
			});

			//批量删除
			$('#btn-batch-del').on('click', function() {
				var checkStatus = table.checkStatus('t-dict');
				var total = checkStatus.data.length;
				layer.confirm('确定删除选中的 ' + total + ' 条数据字典记录吗？', {
					icon: 3
				}, function(index) {
					myutil.ajax({
						url: layui.setter.my.surl + 'admin/system/dict/batchDelete',
						data: {
							ids: myutil.contactBy(checkStatus.data, 'id', ',')
						},
						ok: function(res) {
							layer.alert(res.msg, {
								icon: 1
							});
							fnListTable(myutil.json('#q-form'));
						}
					});
				});
			});

			//测试
			$('#btn-test').on('click', function() {});

		});
	</script>

</html>
